
#include <iostream>
#include "double_link_list.h"
#include "double_link_list_test.h"

using namespace std;

void DoubleLinkListTest::TestInsert() {
    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|                Test DoubleLinkList insertData               |" << endl;
    cout << "|                    测试-双向链表-插入                     |" << endl << endl << endl;

    // 声明band_list(乐队链表)
    DoubleLinkList<string>* band_list = new DoubleLinkList<string>();

    // 插入5个乐队名字
    string band1("The Script");
    string band2("Linkin Park");
    string band3("Starship");
    string band4("Coldplay");
    string band5("黑豹");

    string bands[5] = { band1, band2, band3, band4, band5 };

    for (int i = 0; i < 5; i++) {
        band_list->insertData(i + 1, bands[i]);
    }

    // 打印band_list
    band_list->print();

    cout << "-------------------------------------------------------------" << endl << endl;
}


/*!
 * @brief **测试-双向链表-删除结点**
 * @note
 * 测试-双向链表-删除结点
 * -------------------
 * -------------------
 *
 * -------------------
 * 声明band_list(乐队链表)\n
 * 插入5个乐队名字\n
 * 打印band_list\n
 * 删除当前某个乐队, 并打印, 测试3次\n
 *
 *
 * -------------------
 */
void DoubleLinkListTest::TestRemove() {
    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|                Test DoubleLinkList removeData               |" << endl;
    cout << "|                  测试-双向链表-删除结点                   |" << endl << endl << endl;

    // 声明band_list(乐队链表)
    DoubleLinkList<string>* band_list = new DoubleLinkList<string>();

    // 插入5个乐队名字
    string band1("The Script");
    string band2("Linkin Park");
    string band3("Starship");
    string band4("Coldplay");
    string band5("黑豹");

    string bands[5] = { band1, band2, band3, band4, band5 };

    for (int i = 0; i < 5; i++) {
        band_list->insertData(i + 1, bands[i]);
    }

    // 打印band_list
    band_list->print();

    cout << endl;

    // 删除当前某个乐队, 并打印, 测试3次
    string target_band;
    band_list->removeData(1, target_band);
    cout << "删除当前第1个乐队后:" << endl;
    band_list->print();
    band_list->removeData(4, target_band);
    cout << "删除当前第4个乐队后:" << endl;
    band_list->print();
    band_list->removeData(2, target_band);
    cout << "删除当前第2个乐队后:" << endl;
    band_list->print();

    cout << "-------------------------------------------------------------" << endl << endl;
}


// 测试双向链表搜索
/*!
 * @brief **测试-双向链表-搜索**
 * @note
 * 测试-双向链表-搜索
 * ----------------
 * ----------------
 *
 * ----------------
 * 初始化number_list(整形链表)\n
 * 依次插入1至5\n
 * 依次搜索1至5, 打印对应的结点的地址\n
 *
 * ----------------
 */
void DoubleLinkListTest::TestSearch() {
    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|                Test DoubleLinkList search               |" << endl;
    cout << "|                     测试-双向链表-搜索                    |" << endl << endl << endl;

    // 初始化number_list(整形链表)
    DoubleLinkList<int>* number_list = new DoubleLinkList<int>();

    // 依次插入1至5
    for (int i = 1; i <= 5; i++) {
        int pos = i;
        int data = i;
        number_list->insertData(pos, data);
    }

    // 依次搜索1至5, 打印对应的结点的地址
    for (int i = 1; i <= 5; i++) {
        DoubleLinkNode<int>* addr_by_search = number_list->search(i);

        cout << "Search返回的" << i << "对应的结点地址: " << addr_by_search << endl;
    }

    cout << "-------------------------------------------------------------" << endl << endl;
}


/*!
 * @brief **测试-双向链表-长度**
 * @note
 * 测试-双向链表-长度
 * ----------------
 * ----------------
 *
 * ----------------
 * 初始化number_list(整形链表)\n
 * 依次插入1至5\n
 * 打印链表长度\n
 *
 *
 * ----------------
 */
void DoubleLinkListTest::TestLength() {
    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|                Test DoubleLinkList getLength               |" << endl;
    cout << "|                     测试-双向链表-长度                    |" << endl << endl << endl;

    // 初始化number_list(整形链表)
    DoubleLinkList<int>* number_list = new DoubleLinkList<int>();

    // 依次插入1至5
    for (int i = 1; i <= 5; i++) {
        int pos = i;
        int data = i + 1;
        number_list->insertData(pos, data);
    }

    // 打印链表长度
    cout << "链表长度: " << number_list->getLength() << endl;

    cout << "-------------------------------------------------------------" << endl << endl;
}


/*!
 * @brief **测试-双向链表-清空**
 * @note
 * 测试-双向链表-清空
 * ----------------
 * ----------------
 *
 * ----------------
 * 初始化number_list\n\n
 * 依次插入1至5\n
 * 打印链表长度\n\n
 * 清空链表\n
 * 打印链表长度\n
 *
 *
 * ----------------
 */
void DoubleLinkListTest::TestClear() {
    cout << endl;
    cout << "|------------------------ CyberDash ------------------------|" << endl;
    cout << "|                 Test DoubleLinkList clear               |" << endl;
    cout << "|                     测试-双向链表-清空                    |" << endl << endl << endl;

    // 初始化number_list
    DoubleLinkList<int>* number_list = new DoubleLinkList<int>();

    // 依次插入1至5
    for (int i = 1; i <= 5; i++) {
        int pos = i;
        int data = i + 1;
        number_list->insertData(pos, data);
    }

    // 打印链表长度
    cout << "清空前链表长度: " << number_list->getLength() << endl;

    // 清空链表
    number_list->clear();

    // 打印链表长度
    cout << "清空后链表长度: " << number_list->getLength() << endl;

    cout << "-------------------------------------------------------------" << endl << endl;
}